//路由配置的信息
//引入路由组件(静态引入)
// import Home from '@/pages/Home'
// import Login from '@/pages/Login'
// import Register from '@/pages/Register'
// import Search from '@/pages/Search'
// import Detail from '@/pages/Detail'
// import AddCartSuccess from '@/pages/AddCartSuccess'
// import ShopCart from '@/pages/ShopCart'
// import Trade from '@/pages/Trade'
// import Pay from '@/pages/Pay'
// import PaySuccess from '@/pages/PaySuccess'
// import Center from '@/pages/Center'
// // 二级路由
// import MyOrder from '@/pages/Center/MyOrder'
// import GroupOrder from '@/pages/Center/GroupOrder'

/* 
路由懒加载：
  当打包构建应用时，JavaScript 包会变得非常大，影响页面加载。
  如果我们能把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就会更加高效。
*/

export default [
    {
        name: 'home',
        path: '/home',
        component: () => import('@/pages/Home'), // 动态引入组件
        meta: { isShow: true }  //是否展示页脚footer
    },
    {
        name: 'login',
        path: '/login',
        component: () => import('@/pages/Login'),
    },
    {
        name: 'register',
        path: '/register',
        component: () => import('@/pages/Register')
    },
    {
        name: 'search',
        //在占位符后面加上一个问号，表示params参数可传可不传 
        //如果传递一个空串，使用undefined解决  params:{keyword:'' || undefined}
        path: '/search/:keyword?',
        component: () => import('@/pages/Search'),
        meta: { isShow: true }  //是否展示页脚footer
    },
    {
        name: 'detail',
        path: '/detail/:skuid',
        component: () => import('@/pages/Detail'),
        meta: { isShow: true }  //是否展示页脚footer
    },
    {
        name: 'addcartsuccess',
        path: '/addcartsuccess',
        component:  () => import('@/pages/AddCartSuccess'),
        meta: { isShow: true, isAuth: true }  //是否展示页脚footer
    },
    {
        name: 'shopcart',
        path: '/shopcart',
        component: () => import('@/pages/ShopCart'),
        meta: { isShow: true, isAuth: true }  //是否展示页脚footer
    },
    {
        name: 'trade',
        path: '/trade',
        component: () => import('@/pages/Trade'),
        meta: { isShow: true, isAuth: true },  //是否展示页脚footer
        //路由独享守卫
        beforeEnter(to, from, next) {
            //进入这个路由，只能来自shopcart ,或者刷新
            console.log(from);
            if (from.path == '/shopcart' || from.path == '/') {
                next()
            } else {
                //中断当前导航。URL地址会重置到from路由对应的地址 
                // 从哪来，回哪去
                next(false)
            }
        }
    },
    {
        name: 'pay',
        path: '/pay',
        component: () => import('@/pages/Pay'),
        meta: { isShow: true, isAuth: true },  //是否展示页脚footer
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if (from.path == '/trade' || from.path == '/') {
                next()
            } else {
                next(false)
            }
        }
    },
    {
        name: 'paysuccess',
        path: '/paysuccess',
        component: () => import('@/pages/PaySuccess'),
        meta: { isShow: true, isAuth: true },  //是否展示页脚footer

    },
    {
        name: 'center',
        path: '/center',
        component: () => import('@/pages/Center'),
        meta: { isShow: true, isAuth: true },  //是否展示页脚footer
        children: [
            {
                path: 'myorder',
                component:  () => import('@/pages/Center/MyOrder'),
                meta: { isAuth: true }
            },
            {
                path: 'grouporder',
                component:  () => import('@/pages/Center/GroupOrder'),
                meta: { isAuth: true }
            },
            //重定向
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
    //重定向，在项目跑起来的时候，访问/，立马让他定向到首页
    {
        path: '*',
        redirect: '/home',
    },
]